#ifndef _AUDIO_H_
#define _AUDIO_H_

#include "fastmath.h"
/*#include "circular_buffer.h"*/

extern float samplerate;
extern double inv_samplerate;
extern float smpbufrate;
extern double smpbuftime;
extern float audio_time;

extern float latency;
extern int latency_bufs;

#define SigBuf(_x) ((float*)CellBuf(_x))
#define SigData(_x) (*(float*)(&CellData(_x)))

static inline void dump_signal(float*s) {
	register int i;
	printf("{{");
	for(i=0;i<AUDIOBUF_SZ;i++) {
		printf(" %.4f", s[i]);
	}
	printf(" }}");
}

/*extern circbuf_t* cb_inputs;*/
/*extern circbuf_t* cb_outputs;*/
extern const char ** outports, ** inports;
extern int n_inputs;
extern int n_outputs;

float* get_hard_buf(word handle);

#define cb_in_write(_i, _data) cb_writebuf(&cb_inputs[_i], _data)
#define cb_in_read(_i, _data) cb_readbuf(&cb_inputs[_i], _data)
#define cb_out_write(_i, _data) cb_writebuf(&cb_outputs[_i], _data)
#define cb_out_read(_i, _data) cb_readbuf(&cb_outputs[_i], _data)


struct _wave_t {
	word data_size;
	float pitch;
	word loop_start;
	word loop_end;
	float data;
};

typedef struct _wave_t* wave_t;

#define WAVE_DATA_OFS 4

#endif
